package PVZ;

import java.awt.*;
import java.util.Random;

class getZ implements Runnable{
    public void run(){
        if(Game.i==0){
            try {
                Thread.sleep(20000);
                Game.i++;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        while (Game.ifGame){
            V vs=new V();
            int type=vs.getRandom();
            int y=vs.gety();
            Game.Pictrue1.ypian=y;
            y=y*125+160;
            if(type==1){
                Z1 z1=new Z1(1900,y);
            }
            if(type==2){
                Z2 z2=new Z2(1900,y);
            }
            if(type==3){
                Z3 z3=new Z3(1900,y);
            }
           /*try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Game.p1.repaint();*/
                try {
                    if(Game.s<=300){
                    Thread.sleep(20000);}
                    else {
                        Thread.sleep(15000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        }
    }
}
public class V {
    Random r=new Random();
    public int getRandom(){
        if(Game.s>=400){
          int j=r.nextInt(3);
          j++;
          return j;
        }else {
            return 1;
        }
    }
    public int gety(){
        int y=r.nextInt(5);

        return y;
    }



          /* ActionListener Peatimer=new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if(x<(1920-Game.X_OFFSET)){
                        Graphics g=getGraphics();
                        g.drawImage(Pea,x,y,null);
                        p1.repaint();
                        x=x+20;
                    }else
                    {
                        timer.stop();
                        p1.repaint();
                        x=0;
                        y=0;
                    }
                }
            };
            timer=new Timer(1000,Peatimer);
            timer.start();*/
}
class ReGame implements Runnable{
    public void run(){
        try {
            Thread.sleep(20000);
            Game.i++;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        while (Game.ifGame){
            try {
                Thread.sleep(150);
                Game.i++;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Game.p1.repaint();
        }

    }
}
//换图
class RePicture implements Runnable {
    public void run() {
    while (Game.ifGame){
        try {
            Thread.sleep(100);
            Game.Pictrue1.Z10=Game.Pictrue1.Z11;
            Game.Pictrue1.Z20=Game.Pictrue1.Z21;
            Game.Pictrue1.Z30=Game.Pictrue1.Z31;
            Thread.sleep(100);
            Game.Pictrue1.Z10=Game.Pictrue1.Z12;
            Game.Pictrue1.Z20=Game.Pictrue1.Z22;
            Game.Pictrue1.Z30=Game.Pictrue1.Z32;
            Thread.sleep(100);
            Game.Pictrue1.Z10=Game.Pictrue1.Z13;
            Game.Pictrue1.Z20=Game.Pictrue1.Z23;
            Game.Pictrue1.Z30=Game.Pictrue1.Z33;
            Thread.sleep(100);
            Game.Pictrue1.Z10=Game.Pictrue1.Z13;
            Game.Pictrue1.Z20=Game.Pictrue1.Z23;
            Game.Pictrue1.Z30=Game.Pictrue1.Z33;
            Thread.sleep(100);
            Game.Pictrue1.Z10=Game.Pictrue1.Z14;
            Game.Pictrue1.Z20=Game.Pictrue1.Z24;
            Game.Pictrue1.Z30=Game.Pictrue1.Z34;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    }
    //public int type;
    //public int x,y;
    //public static Boolean ifRe=true;
    /*public RePicture(int type){
        this.type=type;
        //this.x=x;
        //this.y=y;
    }*/
    /*public void run() {
       while (Game.ifGame) {
           for(int x=0;x<1920;x++) {
               for (int y = 0; y < 800; y++) {
                   while (Game.ifZ0[x][y] == 1) {
                       try {
                           if (Game.Ztype[x][y]==10||Game.Ztype[x][y]==11||Game.Ztype[x][y]==12||Game.Ztype[x][y]==13||Game.Ztype[x][y]==14) {
                               Game.Ztype[x][y] = 10;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 11;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 12;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 13;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 14;
                               Thread.sleep(100);
                           }else if(Game.Ztype[x][y]==20||Game.Ztype[x][y]==21||Game.Ztype[x][y]==22||Game.Ztype[x][y]==23||Game.Ztype[x][y]==24){
                               Game.Ztype[x][y] = 20;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 21;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 22;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 23;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 24;
                               Thread.sleep(100);
                           }else if(Game.Ztype[x][y]==30||Game.Ztype[x][y]==31||Game.Ztype[x][y]==32||Game.Ztype[x][y]==33||Game.Ztype[x][y]==34){
                               Game.Ztype[x][y] = 30;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 31;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 32;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 33;
                               Thread.sleep(100);
                               Game.Ztype[x][y] = 34;
                               Thread.sleep(100);
                           }
                       } catch (InterruptedException e) {
                           e.printStackTrace();
                       }
                   }
               }
           }*/
           /*//Graphics g= Game.Pictrue1.Z1.getGraphics();
            if (type == 1) {
                //Game.Pictrue1.Z1=Game.Pictrue1.Z10;
                //g.drawImage(Game.Pictrue1.Z1,x,y,null);
                Game.Ztype[x][y]=10;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //Game.Pictrue1.Z1=Game.Pictrue1.Z1;
                //g.drawImage(Game.Pictrue1.Z1,x,y,null);
                Game.Ztype[x][y]=11;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //Game.Pictrue1.Z1=Game.Pictrue1.Z12;
                //g.drawImage(Game.Pictrue1.Z1,x,y,null);
                Game.Ztype[x][y]=12;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //Game.Pictrue1.Z1=Game.Pictrue1.Z13;
                //g.drawImage(Game.Pictrue1.Z1,x,y,null);
                Game.Ztype[x][y]=13;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //Game.Pictrue1.Z1=Game.Pictrue1.Z14;
                //g.drawImage(Game.Pictrue1.Z1,x,y,null);
                Game.Ztype[x][y]=14;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
}
}*/
}
